﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Common;

namespace Mads.WcfService
{
  internal static class MySqlExtensions
  {
    public static T? GetNullable<T>(
      this DbDataReader reader, Func<int, T> getter, string columnName)
      where T : struct
    {
      int column = reader.GetOrdinal(columnName);
      return reader.IsDBNull(column) ? null : (T?)getter(column);
    }

    public static string GetStringOrNull(
      this DbDataReader reader, string columnName)
    {
      int column = reader.GetOrdinal(columnName);
      return reader.IsDBNull(column) ? null : reader.GetString(column);
    }

  }
}